load("//src/material:config.bzl", "MATERIAL_SCSS_LIBS")
load(
    "//tools:defaults.bzl",
    "markdown_to_html",
    "ng_module",
    "ng_test_library",
    "ng_web_test_suite",
    "sass_binary",
    "sass_library",
)

package(default_visibility = ["//visibility:public"])

exports_files(["theming/_theming.scss"])

ng_module(
    name = "core",
    srcs = glob(
        ["**/*.ts"],
        exclude = ["**/*.spec.ts"],
    ),
    assets = [
        ":selection/pseudo-checkbox/pseudo-checkbox.css",
        ":option/option.css",
        ":option/optgroup.css",
        ":internal-form-field/internal-form-field.css",
    ] + glob(["**/*.html"]),
    deps = [
        "//src:dev_mode_types",
        "//src/cdk",
        "//src/cdk/a11y",
        "//src/cdk/bidi",
        "//src/cdk/coercion",
        "//src/cdk/keycodes",
        "//src/cdk/platform",
        "@npm//@angular/animations",
        "@npm//@angular/core",
        "@npm//@angular/forms",
        "@npm//@angular/platform-browser",
        "@npm//rxjs",
    ],
)

ALL_THEMING_FILES = [
    # The `_core.scss` file needs to be added here too because it depends
    # on the `_all-typography` file.
    "_core.scss",
    "color/_all-color.scss",
    "density/private/_all-density.scss",
    "theming/_all-theme.scss",
    "typography/_all-typography.scss",
]

sass_library(
    name = "core_scss_lib",
    srcs = glob(
        ["**/_*.scss"],
        exclude = ALL_THEMING_FILES,
    ),
    deps = [
        "//:mdc_sass_lib",
        "//src/cdk:sass_lib",
    ],
)

sass_library(
    name = "theming_scss_lib",
    srcs = ALL_THEMING_FILES,
    deps = MATERIAL_SCSS_LIBS + [
        "//src/cdk:sass_lib",
    ],
)

sass_binary(
    name = "pseudo_checkbox_scss",
    src = "selection/pseudo-checkbox/pseudo-checkbox.scss",
    deps = [":core_scss_lib"],
)

sass_binary(
    name = "option_scss",
    src = "option/option.scss",
    deps = [":core_scss_lib"],
)

sass_binary(
    name = "optgroup_scss",
    src = "option/optgroup.scss",
    deps = [":core_scss_lib"],
)

sass_binary(
    name = "internal_form_field_scss",
    src = "internal-form-field/internal-form-field.scss",
    deps = [":core_scss_lib"],
)

# M3 themes
sass_binary(
    name = "azure_blue_prebuilt",
    src = "theming/prebuilt/azure-blue.scss",
    deps = [
        ":theming_scss_lib",
        "//src/material-experimental:sass_lib",
    ],
)

sass_binary(
    name = "rose_red_prebuilt",
    src = "theming/prebuilt/rose-red.scss",
    deps = [
        ":theming_scss_lib",
        "//src/material-experimental:sass_lib",
    ],
)

sass_binary(
    name = "cyan_orange_prebuilt",
    src = "theming/prebuilt/cyan-orange.scss",
    deps = [
        ":theming_scss_lib",
        "//src/material-experimental:sass_lib",
    ],
)

sass_binary(
    name = "magenta_violet_prebuilt",
    src = "theming/prebuilt/magenta-violet.scss",
    deps = [
        ":theming_scss_lib",
        "//src/material-experimental:sass_lib",
    ],
)

# Legacy M2 themes
sass_binary(
    name = "indigo_pink_prebuilt",
    src = "theming/prebuilt/indigo-pink.scss",
    deps = [":theming_scss_lib"],
)

sass_binary(
    name = "deeppurple-amber_prebuilt",
    src = "theming/prebuilt/deeppurple-amber.scss",
    deps = [":theming_scss_lib"],
)

sass_binary(
    name = "pink-bluegrey_prebuilt",
    src = "theming/prebuilt/pink-bluegrey.scss",
    deps = [":theming_scss_lib"],
)

sass_binary(
    name = "purple-green_prebuilt",
    src = "theming/prebuilt/purple-green.scss",
    deps = [":theming_scss_lib"],
)

#################
#  Test targets
#################

ng_test_library(
    name = "unit_test_sources",
    srcs = glob(
        ["**/*.spec.ts"],
        exclude = ["**/*.e2e.spec.ts"],
    ),
    deps = [
        ":core",
        "//src/cdk/keycodes",
        "//src/cdk/platform",
        "//src/cdk/testing/private",
        "//src/material/testing",
        "@npm//@angular/platform-browser",
    ],
)

ng_web_test_suite(
    name = "unit_tests",
    deps = [":unit_test_sources"],
)

markdown_to_html(
    name = "overview",
    srcs = [
        "core.md",
        "ripple/ripple.md",
    ],
)

filegroup(
    name = "source-files",
    srcs = glob(["**/*.ts"]),
)
